package com.barbeque.mall.service;

import com.barbeque.mall.bean.system.*;
import com.barbeque.mall.mapper.MarketPermissionMapper;
import com.barbeque.mall.mapper.MarketRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author why
 * @since 2022/07/19 10:06
 */
@Service
public class AdminAuthServiceImpl implements AdminAuthService {

    @Autowired
    MarketPermissionMapper marketPermissionMapper;

    @Autowired
    MarketRoleMapper marketRoleMapper;

    @Override
    public List<MarketPermission> getPermissionByRoleId(Integer roleId) {
        MarketPermissionExample marketPermissionExample = new MarketPermissionExample();
        MarketPermissionExample.Criteria criteria = marketPermissionExample.createCriteria();
        criteria.andRoleIdEqualTo(roleId);
        criteria.andDeletedEqualTo(false);

        List<MarketPermission> marketPermissions = marketPermissionMapper.selectByExample(marketPermissionExample);

        return marketPermissions;
    }


    @Override
    public List<String> getApiByRoleId(Integer roleId) {
        List<String> apiByRoleId = marketRoleMapper.getApiByRoleId(roleId);
        return apiByRoleId;
    }

    @Override
    public List<MarketRole> getRoleIdName(Integer roleId) {
        MarketRoleExample marketRoleExample = new MarketRoleExample();
        MarketRoleExample.Criteria criteria = marketRoleExample.createCriteria();
        criteria.andIdEqualTo(roleId);
        criteria.andDeletedEqualTo(false);

        List<MarketRole> marketRoles = marketRoleMapper.selectByExample(marketRoleExample);
        return marketRoles;
    }
}
